package com.ruoyi.product.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.product.domain.MallProductRuleCenter;
import com.ruoyi.product.service.IMallProductRuleCenterService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 商品规格中间Controller
 *
 * @author ruoyi
 * @date 2025-07-28
 */
@RestController
@RequestMapping("/center")
public class MallProductRuleCenterController extends BaseController
{
    @Autowired
    private IMallProductRuleCenterService mallProductRuleCenterService;

    /**
     * 查询商品规格中间列表
     */
    @RequiresPermissions("product:center:list")
    @GetMapping("/list")
    public Result<TableDataInfo> list(MallProductRuleCenter mallProductRuleCenter)
    {
        startPage();
        List<MallProductRuleCenter> list = mallProductRuleCenterService.selectMallProductRuleCenterList(mallProductRuleCenter);
        return getDataTable(list);
    }

    /**
     * 导出商品规格中间列表
     */
    @RequiresPermissions("product:center:export")
    @Log(title = "商品规格中间", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MallProductRuleCenter mallProductRuleCenter)
    {
        List<MallProductRuleCenter> list = mallProductRuleCenterService.selectMallProductRuleCenterList(mallProductRuleCenter);
        ExcelUtil<MallProductRuleCenter> util = new ExcelUtil<MallProductRuleCenter>(MallProductRuleCenter.class);
        util.exportExcel(response, list, "商品规格中间数据");
    }

    /**
     * 获取商品规格中间详细信息
     */
    @RequiresPermissions("product:center:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") String id)
    {
        return success(mallProductRuleCenterService.selectMallProductRuleCenterById(id));
    }

    /**
     * 获取商品规格中间详细信息  加载查询框
     */
    @RequiresPermissions("product:center:query")
    @GetMapping(value = "/findSkuByProductId/{productId}")
    public Result findSkuByProductId(@PathVariable("productId") String productId)
    {
        MallProductRuleCenter mallProductRuleCenter = new MallProductRuleCenter();
        mallProductRuleCenter.setProductId(productId);
        return success(mallProductRuleCenterService.selectMallProductRuleCenterList(mallProductRuleCenter));
    }

    /**
     * 新增商品规格中间
     */
    @RequiresPermissions("product:center:add")
    @Log(title = "商品规格中间", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody MallProductRuleCenter mallProductRuleCenter)
    {
        return toAjax(mallProductRuleCenterService.insertMallProductRuleCenter(mallProductRuleCenter));
    }

    /**
     * 修改商品规格中间
     */
    @RequiresPermissions("product:center:edit")
    @Log(title = "商品规格中间", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody MallProductRuleCenter mallProductRuleCenter)
    {
        return toAjax(mallProductRuleCenterService.updateMallProductRuleCenter(mallProductRuleCenter));
    }

    /**
     * 删除商品规格中间
     */
    @RequiresPermissions("product:center:remove")
    @Log(title = "商品规格中间", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public Result remove(@PathVariable String[] ids)
    {
        return toAjax(mallProductRuleCenterService.deleteMallProductRuleCenterByIds(ids));
    }
}
